<!--  -->
<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>评价管理</el-breadcrumb-item>
      <el-breadcrumb-item>评价列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card>
      <el-row :gutter="24">
        <el-col :span="6">
          <Menu @tree-node-click="treeNodeClick"></Menu>
        </el-col>
        <el-col :span="18">
          <div class="text item">
            <el-select v-model="selectProid" placeholder="请选择"  @change="getProid">
              <el-option
                v-for="item in productList"
                :key="item.proid"
                :label="item.proName"
                :value="item.proid"
               >
              </el-option>
            </el-select>
            </div
        >
        <!-- 评价列表区 -->
      <el-table :data="commentInfo" highlight-current-row border>
        <el-table-column type="index" width="40"> </el-table-column>
        <el-table-column property="commentType" label="评价等级" width="90">
           <template slot-scope="scope">
            <el-tag v-show="scope.row.star>=3" type="success">好评</el-tag>
            <el-tag v-show="scope.row.star<=2" type="info">差评</el-tag>
          </template>
        </el-table-column> 
        <el-table-column property="proName" label="商品名" width="150">
           <template slot-scope="scope">
            <div class="commentTitle">{{ scope.row.proName }}</div>
          </template>
        </el-table-column>
        <el-table-column label="评价内容" property="description">
          <template slot-scope="scope">
            <div class="commentContent">{{ scope.row.description }}</div>
          </template>
        </el-table-column>
        <!-- <el-table-column property="star" label="评价星级" width="100">
        </el-table-column> -->
        <el-table-column property="likesCount" label="点赞量" width="70"> </el-table-column>
        <!-- <el-table-column property="replyCount" label="回复数" width="70"> </el-table-column> -->
        <el-table-column property="createTime" label="评价时间" width="170">
          <template slot-scope="scope">{{scope.row.createTime  | dateFormat}}
          </template> </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="showEditDialog(scope.row)"
              >回复</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pageIndex"
        :page-sizes="[3, 5,10]"
        :page-size="queryInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      
      </el-col>
      </el-row>
      
    </el-card>
    <!-- 回复评价对话框 -->
    <el-dialog
      title="回复内容"
      width="50%"
      :visible.sync="dialogEditVisible"
    >
      <el-form
        :model="updateMseeage"
        ref="editFormRef"
        label-width="100px"
        class="demo-ruleForm"
      >
      <el-form-item label="评价内容" prop="description">
        <el-input v-model="updateMseeage.description" disabled></el-input>
        </el-form-item>
        <el-form-item label="回复消息" prop="replyInfo">
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            v-model="updateMseeage.replyInfo">
          </el-input>
          <!-- <textarea
            v-model="updateCommentInfo.resources"
            class="updateCommentContent"
          ></textarea> -->
        </el-form-item> 
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogEditVisible = false">取 消</el-button>
        <el-button type="primary" @click="updataComment">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Menu from '../product/components/Menu.vue'
export default {
  name: "Comment",
  data() {
    return {
      queryInfo: {
        key: "",
        // 当前页码
        pageIndex: 1,
        // 当前每页显示多少条数据
        pageSize: 5,
      },
      dialogEditVisible: false,
      total: 0,
      selectCatId :'',
      // 选中的proid
      selectProid:'',
      // 评价信息
      commentInfo: [],
      // 回复框显示的信息
      updateMseeage:{
        replyInfo:'',
        description:''
      },
      // 修改信息
      updateCommentInfo: {
      skuId:'',
      proId :'',
      parentId:'',
      description :'',
      resources :'',
      },
      productList:[],
    };
  },
  created() {
    // this.getCommentList();
    this.getProductList();
  },
  components:{Menu},
  methods: {
    // 子组件树被点击传回来数据 node节点
    treeNodeClick(data,node,component){
      // console.log(data,node,component)
      this.selectCatId = data.catId
      this.getProductList()
    },
    // 获取商品数据
    async  getProductList(){
        this.productList = []
        const {data:res}  = await this.$http.get(`/dqxmall/prosysproinfo/getAllShopByCatalogId?catalogId=${this.selectCatId}`) 
        // console.log(res)
        // this.total = res.page.totalCount
        res.page.list.forEach(item=>{
            var data = {}
            data.proid = item.id
            data.proName = item.proName
            this.productList.push(data)
        })
        // console.log(this.productList)
    },
    getProid(){
      // console.log(this.selectProid)
      this.getCommentList();
    },
    // 监听pageSize改变
    handleSizeChange(newSize) {
      // console.log(newSize)
      this.queryInfo.pageSize = newSize;
      this.getCommentList();
    },
    // 监听页码值改变事件
    handleCurrentChange(newPage) {
      // console.log(newPage)
      this.queryInfo.pageIndex = newPage;
      this.getCommentList();
    },
    // 获取评价列表
    async  getCommentList() {
       const {data:res} = await this.$http.get(`/dqxmall/prosysprocomment/getComment/${this.selectProid}?page=${this.queryInfo.pageIndex}&limit=${this.queryInfo.pageSize}`)
       console.log("评价",res) 
       this.total = res.page.totalCount
       this.commentInfo = res.page.list
    },
    // 回复评价信息
    async  updataComment() {
      this.updateCommentInfo.description = this.updateMseeage.replyInfo
      const{data:res} = await this.$http.post(`/dqxmall/prosysprocomment/save`,this.updateCommentInfo)
      // console.log(res)
      if(res.code !== 0){
        this.$message.error("回复失败")
      }
      this.$message.success("回复成功")
      this.dialogEditVisible = false;
    },
    // 修改对话框显示
    async  showEditDialog(row) {
      
      // this.updateCommentInfo = row
      this.updateCommentInfo.skuId = row.skuId;
      this.updateCommentInfo.proId = row.proId;
      this.updateCommentInfo.commentType = 1;
      this.updateCommentInfo.parentId = row.id;
      this.updateCommentInfo.description = '';
      if(row.replyCount){
        const {data:res} = await this.$http.get(`/dqxmall/prosysprocomment/info/${row.id}`)
        // console.log("huifuxianshi",res)
        this.updateMseeage.replyInfo =res.prosysProComment[res.prosysProComment.length-1].description
      }
      this.updateMseeage.description = row.description
      this.dialogEditVisible = true;
    },
    // 关闭修改对话框
    // editDialogClose() {
    //   this.$refs.editFormRef.resetFields();
    // },
    
  },
};
</script>
<style lang="less" scoped>
.headimag {
  height: 90px;
  width: 90px;
}
.updateCommentContent {
  width: 530px;
}
.commentContent,
.commentTitle {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
</style>
